<template>
  <div class="post-list">
    <PostItem
      v-for="post in posts"
      :key="post.id"
      :post="post"
      :is-active="activeCommentId === post.id"
      @toggle-comments="$emit('toggle-comments', post.id)"
    />
    <button class="load-more" @click="$emit('load-more')">加载更多</button>
  </div>
</template>

<script setup>
import { defineProps, defineEmits } from 'vue'
import PostItem from './PostItem.vue'

defineProps({
  posts: {
    type: Array,
    required: true
  },
  activeCommentId: {
    type: Number,
    default: null
  }
})

defineEmits(['load-more', 'toggle-comments'])
</script>

<style scoped>
.post-list {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.load-more {
  margin-top: 20px;
  padding: 10px 20px;
  background-color: #1e40af;
  color: white;
  border: none;
  border-radius: 4px;
  font-size: 16px;
  cursor: pointer;
  align-self: center;
  transition: background-color 0.3s;
}

.load-more:hover {
  background-color: #2563eb;
}
</style>
